<script>
// app.js
const _api = require('./utils/api.js');
const apiurl = require('./utils/apiurl/public.js');
export default {
    data() {
        return {};
    },
    onLaunch() {
        // 展示本地存储能力
        const logs = uni.getStorageSync('logs') || [];
        logs.unshift(Date.now());
        uni.setStorageSync('logs', logs);
        uni.getSystemInfo({
            success: (e) => {
                this.globalData.StatusBar = e.statusBarHeight;
				// #ifdef MP-WEIXIN
                let capsule = uni.getMenuButtonBoundingClientRect();
                if (capsule) {
                    this.globalData.Custom = capsule;
                    this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
                } else {
                    this.globalData.CustomBar = e.statusBarHeight + 50;
                }
				// #endif
            }
        });
		// #ifdef MP-WEIXIN
        uni.login({
            success: (res) => {
                var code = res.code;
                if (code) {
                    uni.getUserInfo({
                        success: (ures) => {
                            _api.post(apiurl.login, {
                                js_code: code,
                                encryptedData: ures.encryptedData,
                                iv: ures.iv
                            }).then((loginres) => {
                                uni.setStorageSync('token', loginres.data.data.token);
                                const obj = uni.getLaunchOptionsSync();
                                const query = obj.query; // 包含地址栏参数的对象
                                console.log('启动小程序的路径:', obj);
                                if (query.clue_token && query.project_id) {
                                    let params = {
                                        clue_token: query.clue_token,
                                        project_id: query.project_id,
                                        promotion_id: query.promotion_id,
                                        advertiser_id: query.advertiser_id,
                                        req_id: query.req_id,
                                        data: JSON.stringify(query),
                                        mid1: query.mid1,
                                        mid2: query.mid2,
                                        mid3: query.mid3,
                                        mid4: query.mid4,
                                        mid5: query.mid5,
                                        type: 'app'
                                    };
                                    _api.post('index/user/data_report', params).then((qdres) => {});
                                } else {
                                    let params = {
                                        data: JSON.stringify(obj),
                                        type: 'qqad'
                                    };
                                    _api.post('index/user/data_report', params).then((qdres) => {});
                                }
                                //获取用户信息
                                _api.get(apiurl.userinfo).then((res) => {
                                    if (res.data.code == 0) {
                                        uni.setStorageSync('getuser', res.data.data);
                                    }
                                });
                            });
                        }
                    });
                }
            }
        });
		// #endif
        if (uni.canIUse('getUpdateManager')) {
            const updateManager = uni.getUpdateManager();
            updateManager.onCheckForUpdate(function (res) {
                if (res.hasUpdate) {
                    updateManager.onUpdateReady(function () {
                        uni.showModal({
                            title: '更新提示',
                            content: '新版本已经准备好，是否重启应用？',
                            success: function (res) {
                                if (res.confirm) {
                                    updateManager.applyUpdate();
                                }
                            }
                        });
                    });
                    updateManager.onUpdateFailed(function () {
                        uni.showModal({
                            title: '已经有新版本了哟~',
                            content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
                        });
                    });
                }
            });
        } else {
            uni.showModal({
                title: '提示',
                content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
            });
        }
    },
    globalData: {
        userInfo: null,
        ColorList: [
            {
                title: '嫣红',
                name: 'red',
                color: '#e54d42'
            },
            {
                title: '桔橙',
                name: 'orange',
                color: '#f37b1d'
            },
            {
                title: '明黄',
                name: 'yellow',
                color: '#fbbd08'
            },
            {
                title: '橄榄',
                name: 'olive',
                color: '#8dc63f'
            },
            {
                title: '森绿',
                name: 'green',
                color: '#39b54a'
            },
            {
                title: '天青',
                name: 'cyan',
                color: '#1cbbb4'
            },
            {
                title: '海蓝',
                name: 'blue',
                color: '#0081ff'
            },
            {
                title: '姹紫',
                name: 'purple',
                color: '#6739b6'
            },
            {
                title: '木槿',
                name: 'mauve',
                color: '#9c26b0'
            },
            {
                title: '桃粉',
                name: 'pink',
                color: '#e03997'
            },
            {
                title: '棕褐',
                name: 'brown',
                color: '#a5673f'
            },
            {
                title: '玄灰',
                name: 'grey',
                color: '#8799a3'
            },
            {
                title: '草灰',
                name: 'gray',
                color: '#aaaaaa'
            },
            {
                title: '墨黑',
                name: 'black',
                color: '#333333'
            },
            {
                title: '雅白',
                name: 'white',
                color: '#ffffff'
            }
        ]
    }
};
</script>
<style>
@import './colorui/main.css';
@import './colorui/icon.css'; /**app.wxss**/
/*引入colorui组件*//*引入colorui组件*/
pag {
    color: #767676;
    background-color: #fff !important;
}
.topbox {
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    z-index: 1000;
    background: #ffffff;
}
.emptybox {
    flex-direction: column;
    margin-top: 120rpx;
    align-items: center;
    justify-content: center;
}
.emptybox image {
    width: 40%;
}
</style>
